package com.inspur.cloud.entity.dataspace;

import java.util.HashMap;
import java.util.Map;

public class UserThreadLocal {

    private static ThreadLocal<Map<String, Object>> local = new ThreadLocal<Map<String, Object>>();

    private static void set(Map<String, Object> map) {
        local.set(map);
    }

    private static Map<String, Object> get() {
        return local.get();
    }

    public static void remove() {
        local.remove();
    }

    public static void setValue(String key, Object value) {
        Map<String, Object> map = get();
        if (map == null) {
            map = new HashMap<String, Object>();
        }
        map.put(key, value);
        set(map);
    }

    public static String getValue(String key) {
        Map<String, Object> map = get();
        if (map == null || map.get(key) == null) {
            return "";
        } else {
            return map.get(key).toString();
        }
    }
}
